package spbun.fileclean;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.List;

import org.apache.log4j.Logger;

import spbun.fileclean.anaylize.FileAnaylize;
import spbun.fileclean.common.FileUtil;
import spbun.fileclean.dto.FileInfo;

/**
 * 分析类
 * 
 * @author spbun
 *
 */
public class FileCleanAnaylize {

	/** 日志 */
	private static final Logger LOG = Logger.getLogger(FileCleanAnaylize.class);

	public static void main(String[] args) throws Exception {

		File sourceFile = new File(FileUtil.getWebAppBasePath(), "fileclean.imgnew.obj");

		List<FileInfo> infos = loadObj(sourceFile);

		FileAnaylize fa = new FileAnaylize(infos);
		fa.forderLike();
		// fa.fileLike();
		// fa.bigSameFile();

	}

	@SuppressWarnings("unchecked")
	private static List<FileInfo> loadObj(File sourceFile)
			throws FileNotFoundException, IOException, ClassNotFoundException {

		long start = System.currentTimeMillis();
		LOG.debug("开始读取文件");

		try (FileInputStream fis = new FileInputStream(sourceFile);
				ObjectInputStream ois = new ObjectInputStream(fis);) {

			List<FileInfo> result = (List<FileInfo>) ois.readObject();

			long end = System.currentTimeMillis();
			LOG.debug("读取完成,耗时：" + (end - start) / 1000 + "秒");

			return result;
		}
	}
}
